package com.zgm.ch05.aop.after._3_5_4_2;

import java.lang.reflect.Method;

import org.springframework.aop.AfterReturningAdvice;

public class WeakKeyCheckAdvice implements AfterReturningAdvice {

	public void afterReturning(Object returnValue, Method method,
			Object[] args, Object target) throws Throwable {

		if(target instanceof KeyGenerator && ("getKey".equals(method.getName()))) {
			long key = (Long) returnValue;
			
			if (key == KeyGenerator.WEAK_KEY) {
				throw new SecurityException("生成了一个弱密钥，请重试！");
			}
		}
	}
	
	

}
